package com.ruoyi.buss.point.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.buss.point.domain.UpdatePoints;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.buss.point.domain.ActMangagerPoint;
import com.ruoyi.buss.point.service.IActMangagerPointService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 第一阶段网格化营销活动方案Controller
 * 
 * @author sxy
 * @date 2022-05-03
 */
@RestController
@RequestMapping("/managerPoint")
public class ActMangagerPointController extends BaseController
{
    @Autowired
    private IActMangagerPointService actMangagerPointService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询第一阶段网格化营销活动方案列表
     */
    @PreAuthorize(hasPermi = "buss:managerPoint:list")
    @GetMapping("/list")
    public TableDataInfo list(ActMangagerPoint actMangagerPoint)
    {
        LoginUser userInfo = tokenService.getLoginUser();
        startPage();
        List<ActMangagerPoint> list = actMangagerPointService.selectActMangagerPointList(actMangagerPoint, userInfo);
        return getDataTable(list);
    }

    /**
     * 导出第一阶段网格化营销活动方案列表
     */
    @PreAuthorize(hasPermi = "buss:managerPoint:export")
    @Log(title = "第一阶段网格化营销活动方案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ActMangagerPoint actMangagerPoint) throws IOException
    {
        LoginUser userInfo = tokenService.getLoginUser();
        List<ActMangagerPoint> list = actMangagerPointService.selectActMangagerPointList(actMangagerPoint, userInfo);
        ExcelUtil<ActMangagerPoint> util = new ExcelUtil<ActMangagerPoint>(ActMangagerPoint.class);
        util.exportExcel(response, list, "第一阶段网格化营销活动方案数据");
    }

    /**
     * 获取第一阶段网格化营销活动方案详细信息
     */
    @PreAuthorize(hasPermi = "buss:managerPoint:query")
    @GetMapping(value = "/{userName}")
    public AjaxResult getInfo(@PathVariable("userName") String userName)
    {
        return AjaxResult.success(actMangagerPointService.selectActMangagerPointById(userName));
    }

    /**
     * 新增第一阶段网格化营销活动方案
     */
    @PreAuthorize(hasPermi = "buss:managerPoint:add")
    @Log(title = "第一阶段网格化营销活动方案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActMangagerPoint actMangagerPoint)
    {
        return toAjax(actMangagerPointService.insertActMangagerPoint(actMangagerPoint));
    }

    /**
     * 修改第一阶段网格化营销活动方案
     */
    @PreAuthorize(hasPermi = "buss:managerPoint:edit")
    @Log(title = "第一阶段网格化营销活动方案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActMangagerPoint actMangagerPoint)
    {
        return toAjax(actMangagerPointService.updateActMangagerPoint(actMangagerPoint));
    }

    /**
     * 删除第一阶段网格化营销活动方案
     */
    @PreAuthorize(hasPermi = "buss:managerPoint:remove")
    @Log(title = "第一阶段网格化营销活动方案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userNames}")
    public AjaxResult remove(@PathVariable String[] userNames)
    {
        return toAjax(actMangagerPointService.deleteActMangagerPointByIds(userNames));
    }

    /**
     * 维护存量客户信息积分明细
     */
    @PreAuthorize(hasPermi = "buss:managerPoint:updatePoint")
    @GetMapping("/updatePoint")
    public TableDataInfo updatePoint(ActMangagerPoint actMangagerPoint)
    {
        LoginUser userInfo = tokenService.getLoginUser();
        startPage();
        List<UpdatePoints> list = actMangagerPointService.updatePoint(actMangagerPoint, userInfo);
        return getDataTable(list);
    }

    /**
     * 导出维护存量客户信息积分明细
     */
    @PreAuthorize(hasPermi = "buss:updatePoint:export")
    @Log(title = "第一阶段网格化营销活动方案", businessType = BusinessType.EXPORT)
    @PostMapping("/updatePoint/export")
    public void updatePointExport(HttpServletResponse response, ActMangagerPoint actMangagerPoint) throws IOException
    {
        LoginUser userInfo = tokenService.getLoginUser();
        List<UpdatePoints> list = actMangagerPointService.updatePoint(actMangagerPoint, userInfo);
        ExcelUtil<UpdatePoints> util = new ExcelUtil<UpdatePoints>(UpdatePoints.class);
        util.exportExcel(response, list, "第一阶段网格化营销活动方案数据");
    }

    /**
     * 新增客户信息积分明细
     */
    @PreAuthorize(hasPermi = "buss:managerPoint:addPoint")
    @GetMapping("/addPoint")
    public TableDataInfo addPoint(ActMangagerPoint actMangagerPoint)
    {
        LoginUser userInfo = tokenService.getLoginUser();
        startPage();
        List<UpdatePoints> list = actMangagerPointService.addPoint(actMangagerPoint, userInfo);
        return getDataTable(list);
    }

    /**
     * 导出新增客户信息积分明细
     */
    @PreAuthorize(hasPermi = "buss:addPoint:export")
    @Log(title = "第一阶段网格化营销活动方案", businessType = BusinessType.EXPORT)
    @PostMapping("/addPoint/export")
    public void addPointExport(HttpServletResponse response, ActMangagerPoint actMangagerPoint) throws IOException
    {
        LoginUser userInfo = tokenService.getLoginUser();
        List<UpdatePoints> list = actMangagerPointService.addPoint(actMangagerPoint, userInfo);
        ExcelUtil<UpdatePoints> util = new ExcelUtil<UpdatePoints>(UpdatePoints.class);
        util.exportExcel(response, list, "第一阶段网格化营销活动方案数据");
    }

    /**
     * 授信积分明细
     */
    @PreAuthorize(hasPermi = "buss:managerPoint:sxPoint")
    @GetMapping("/sxPoint")
    public TableDataInfo sxPoint(ActMangagerPoint actMangagerPoint)
    {
        LoginUser userInfo = tokenService.getLoginUser();
        startPage();
        List<UpdatePoints> list = actMangagerPointService.sxPoint(actMangagerPoint, userInfo);
        return getDataTable(list);
    }

    /**
     * 导出授信积分明细
     */
    @PreAuthorize(hasPermi = "buss:sxPoint:export")
    @Log(title = "第一阶段网格化营销活动方案", businessType = BusinessType.EXPORT)
    @PostMapping("/sxPoint/export")
    public void sxPointExport(HttpServletResponse response, ActMangagerPoint actMangagerPoint) throws IOException
    {
        LoginUser userInfo = tokenService.getLoginUser();
        List<UpdatePoints> list = actMangagerPointService.sxPoint(actMangagerPoint, userInfo);
        ExcelUtil<UpdatePoints> util = new ExcelUtil<UpdatePoints>(UpdatePoints.class);
        util.exportExcel(response, list, "第一阶段网格化营销活动方案数据");
    }

    /**
     * 用信积分明细
     */
    @PreAuthorize(hasPermi = "buss:managerPoint:yxPoint")
    @GetMapping("/yxPoint")
    public TableDataInfo yxPoint(ActMangagerPoint actMangagerPoint)
    {
        LoginUser userInfo = tokenService.getLoginUser();
        startPage();
        List<UpdatePoints> list = actMangagerPointService.yxPoint(actMangagerPoint, userInfo);
        return getDataTable(list);
    }

    /**
     * 导出用信积分明细
     */
    @PreAuthorize(hasPermi = "buss:yxPoint:export")
    @Log(title = "第一阶段网格化营销活动方案", businessType = BusinessType.EXPORT)
    @PostMapping("/yxPoint/export")
    public void yxPointExport(HttpServletResponse response, ActMangagerPoint actMangagerPoint) throws IOException
    {
        LoginUser userInfo = tokenService.getLoginUser();
        List<UpdatePoints> list = actMangagerPointService.yxPoint(actMangagerPoint, userInfo);
        ExcelUtil<UpdatePoints> util = new ExcelUtil<UpdatePoints>(UpdatePoints.class);
        util.exportExcel(response, list, "第一阶段网格化营销活动方案数据");
    }
}
